﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Input;
using System.Drawing;
using System.Windows;
using System.Windows.Media;

namespace editor
{
    public class CommentBox : System.Windows.Controls.TextBox, UIViewProtocol
    {

        public CommentBox()
        {
            this.PreviewMouseDown += new MouseButtonEventHandler(MouseButtonDown);

            this.MaxLength = 120;
            this.MaxWidth = 140;
            this.MaxHeight = 120;

            //рамка text box
            Thickness fg = new Thickness(5);
            this.BorderThickness = fg;
            this.BorderBrush = System.Windows.Media.Brushes.Chocolate;

            //форму 
            Rect r = new Rect(0, 0, 120, 120);
            this.Clip = new RectangleGeometry(r, 10, 10);

            this.MinLines = 1;
            this.MaxLines = 3;
            //возможность переноса текста в строке
            this.TextWrapping = TextWrapping.Wrap;
            this.Text = "комментарий";

            MainWindow.shared().commentsList.Add(this);
        }

        public CommentBox initWithPoint(System.Windows.Point origin)
        {
            //позиция на канвасе
            Canvas.SetTop(this, origin.Y);
            Canvas.SetLeft(this, origin.X);

            return this;
        }

        public UIViewProtocol copy()
        {
            CommentBox copy = new CommentBox();
            copy.initWithPoint(new System.Windows.Point(Canvas.GetLeft(this), Canvas.GetTop(this)));
            copy.Text = this.Text;

            MainWindow.shared().mainCanvas.Children.Add(copy);

            return (UIViewProtocol)copy;
        }

        public void move(System.Windows.Point origin)
        {
            Canvas mainCanvas = MainWindow.shared().mainCanvas;

            Canvas.SetTop((this), origin.Y);
            Canvas.SetLeft((this), origin.X);
        }


        private void MouseButtonDown(object sender, MouseButtonEventArgs e)
        {
            MainWindow.shared().objectCaptured(this, e.GetPosition(MainWindow.shared().mainCanvas));
        }

        public void rmObject()
        {
            MainWindow.shared().mainCanvas.Children.Remove(this);
        }
    }
}
